let fs = require('fs');
let path = require('path')
const mulu="D:/work/AR/glb/hours"
const col='http://192.168.40.88:984/hours/'
// 递归获取全部文件
const getFile = (src, arr = []) => {
    let paths = fs.readdirSync(src); // 同步读取当前目录
    for (var i = 0; i < paths.length; i++) {
        const pathFile = paths[i]
        var _src = (src + '/' + pathFile).replace('//', '/');
        const stat = fs.statSync(_src)
        if (stat.isDirectory()) {
            getFile(_src, arr)
        } else {
            arr.push(_src)
        }
    }
    return arr
}


async function compress(path,outpath) {
    var filePaths = getFile(path)
    console.log(filePaths)
    const url=filePaths.map((v)=>{
        v =col+ v.split('/').pop()
        const obj={
            url:v,
            position:[]
        }
        return obj
    })
    console.log(url)
    const str = JSON.stringify(url, "", "\t")
    const objstr = 'export const gltfsList=' + str

    
fs.writeFile(__dirname + "/gltfs.ts", objstr, function (err) {
    if (err) {
        return console.log('文件写入失败！' + err.message)
    }
    console.log('文件写入成功！')
})

}

compress(mulu)